const jwt = require('jsonwebtoken');
const secret = "%^^&GTUYH&*";

let genToken = (data, exprire = 7) => {
    let expiresIn = exprire * 24 + 'h'; // 默认有效期7天
    return jwt.sign({data}, secret, { expiresIn});
}

let parseToken = (token) => {
    try{
        var decoded = jwt.verify(token, secret);
        return decoded;
    }catch(e){
        return false;
    }
}



module.exports = {
    genToken,parseToken
};
